import React, { useEffect, useState } from 'react';
import { BrowserRouter as Router, Route, Switch, useLocation } from 'react-router-dom'
import routes from '@/router';
import { ConfigProvider, Input } from 'zarm';
import zhCN from 'zarm/lib/config-provider/locale/zh_CN';
import NavBar from '@/components/Nav';

function App() {

  const [showNav, setShowNav] = useState(false);
  const needNav = ['/', '/data', '/user']
  const { pathname } = useLocation()
  useEffect(() => {
    setShowNav(needNav.includes(pathname))
  }, [pathname])

  return (
    <ConfigProvider primaryColor={'#007fff'} locale={zhCN}>
      <>
        <Switch>
          {
            routes.map(route => <Route
              path={route.path}
              component={route.component}
              key={route.component + route.path}
              exact></Route>)
          }
        </Switch>
        <NavBar showNav={showNav}></NavBar>
      </>
    </ConfigProvider>
  )
}

export default App
